import React, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'

const useLogin = () => {
    const token = localStorage.getItem('token')
    const [islogin, setIslogin] = useState(false)
    const nav = useNavigate()
    useEffect(() => {
        if (token) {
            setIslogin(true)
        }
        else {
            setIslogin(false)
            nav('/login')
        }
    },[])
    return { islogin: islogin }
}

export default useLogin
